<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 编写 getAverageAge(users) 函数，该函数获取一个具有 age 属性的对象数组，并返回平均年龄。
        // 平均值的计算公式是(age1 + age2 + ... + ageN) / N。
        let arr = [
            { name: "John", age: 25 },
            { name: "Pete", age: 30 },
            { name: "Mary", age: 28 }
        ];

        function getAverageAge(arr) {
            let newArr = arr.map((obj) => {
                return obj.age;
            })

            let sum = 0;
            for (let i = 0; i < newArr.length; i++) {
                sum += newArr[i];
            }
            return Math.ceil(sum / newArr.length);
        }
        console.log(getAverageAge(arr));
    </script>
</body>

</html>